Palindrome Partitioning
Question
None
Example 1
None
Solution
- ▭
- ▯
all//Palindrome Partitioning.py
def isPalindrome(string):
left, right = 0, len(string)-1
while right >= left:
if string[left] != string[right]:
return False
left += 1
right -= 1
return True
def palindromePartitioning(s):
res = []
if len(s) == 0:
return [[]]
for i in range(1, len(s)+1):
prefix = s[0:i]
if isPalindrome(prefix):
for j in palindromePartitioning(s[i:]):
res.append([prefix] + j)
return res
# Driver Code
s = "nitin"
print(palindromePartitioning(s))
all//Palindrome Partitioning.py
def isPalindrome(string):
left, right = 0, len(string)-1
while right >= left:
if string[left] != string[right]:
return False
left += 1
right -= 1
return True
def palindromePartitioning(s):
res = []
if len(s) == 0:
return [[]]
for i in range(1, len(s)+1):
prefix = s[0:i]
if isPalindrome(prefix):
for j in palindromePartitioning(s[i:]):
res.append([prefix] + j)
return res
# Driver Code
s = "nitin"
print(palindromePartitioning(s))